from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
from api_test.testcases.user_action.login_test import TestCaseLogin


class TestOpenShop(HttpRunner):
    config = Config("开店").base_url("${get_http_host()}").verify(False)

    teststeps = [
        Step(
            RunTestCase("TestCaseLogin")
            .with_variables(
                **{"phone": "${ENV(UserName)}", "password": "${ENV(Password)}"}
            )
            .call(TestCaseLogin)
            .export(*["token"])
        ),
        Step(
            RunRequest("创建店铺")
            .post("/shop/fastOpenShop")
            .with_headers(**{"OKCLOUD-TOKEN": "$token"})
            .with_json(
                {
                    "addressDetails": "5号楼-801",
                    "addressInfo": "北京北京市朝阳区北路甲一号",
                    "cityCode": "北京市",
                    "headImg": "123.jpg",
                    "latitude": 39.913275,
                    "linkMan": "王小二",
                    "linkPhone": "13945878451",
                    "longitude": 116.403802,
                    "provinceCode": "北京",
                    "regionCode": "朝阳区",
                    "shopMode": "1",
                    "shopName": "HttprunnerShop",
                    "shopType": "0"
                }
            )
            .validate()
            .assert_equal("body.code", 200)
        ),
    ]
